import {createRouter, createWebHistory} from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Order from '../views/Order'
import UserInfo from '../views/UserInfo'
//后台
import BackStageLogin from '../views/backstage/BackStageLogin'
import BackStageHome from '../views/backstage/BackStageHome'
import BackStageUserRole from '../views/backstage/BackStageUserRole'
import BackStageRole from '../views/backstage/BackStageRole'
import BackStageCommodity from '../views/backstage/BackStageCommodity'
import BackStageCommodityType from '../views/backstage/BackStageCommodityType'
import BackStageShopCart from '../views/backstage/BackStageShopCart'
import BackStageOrder from '../views/backstage/BackStageOrder'
import request from "@/utils/request";

const routes = [
    {
        path: '/',
        name: 'home',
        component: HomeView
    },
    {
        path: '/shopCart',
        name: 'shopCart',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/ShopCart.vue')
    },
    {
        path: '/order',
        name: 'order',
        component: Order
    },
    {
        path: '/userInfo',
        name: 'userInfo',
        component: UserInfo
    },
    //后台路由
    {
        path: '/backstage/login',
        name: 'backStageLogin',
        component: BackStageLogin
    },
    {
        path: '/backstage/home',
        name: 'backStageHome',
        component: BackStageHome
    },
    // {
    //     path: '/backstage/userManagement',
    //     name: 'backStageLogin',
    //     component: BackStageLogin
    // },
    // /backstage/role">权限管理</el
    // /backstage/home">用户管理</el
    // /backstage/commodity">商品管
    // /backstage/commodityType"
    // /backstage/shopCart">购物车管
    // /backstage/order">订单管理</e
    {
        path: '/backstage/userRole',
        name: 'backStageUserRole',
        component: BackStageUserRole
    },
    {
        path: '/backstage/role',
        name: 'backStageRole',
        component: BackStageRole
    },
    {
        path: '/backstage/commodity',
        name: 'backStageCommodity',
        component: BackStageCommodity
    },
    {
        path: '/backstage/commodityType',
        name: 'backStageCommodityType',
        component: BackStageCommodityType
    },
    {
        path: '/backstage/shopCart',
        name: 'backStageShopCart',
        component: BackStageShopCart
    },
    {
        path: '/backstage/order',
        name: 'backStageOrder',
        component: BackStageOrder
    },
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

// router.beforeEach((to, from, next) => {
//     if (to.path.startsWith('getUser')) {
//         window.location.removeItem("access-user")
//         next()
//     } else {
//         var user
//         if (localStorage.getItem("access-user") != null) {
//             user = JSON.parse(window.localStorage.getItem("access-user"))
//         } else {
//             user = null;
//         }
//         if (!user) {
//             next({path: '/'});
//         } else {
//             //校验token合法性
//             request.get("http://localhost:9090/checkToken", {
//                 headers: {
//                     token: user.token
//                 }
//             }).then(res => {
//                 console.log(res)
//                 if (!res.data) {
//                     console.log("校验失败");
//                     next({path: '/'});
//                 }
//             })
//             next();
//         }
//     }
// })

export default router
